package cn.monkey.family.server.domain.shop.order;

import cn.monkey.family.data.crud.repository.QueryDslQueryRequestRepository;
import cn.monkey.family.data.shop.order.OrderDetail;
import cn.monkey.family.data.shop.order.OrderDetailQueryRequest;
import cn.monkey.family.data.shop.order.QOrderDetail;
import com.google.common.base.Strings;
import com.querydsl.core.BooleanBuilder;
import com.querydsl.core.types.Predicate;
import org.springframework.data.repository.NoRepositoryBean;


@NoRepositoryBean
public interface OrderDetailRepository extends QueryDslQueryRequestRepository<OrderDetail, String, OrderDetailQueryRequest> {

    @Override
    default Predicate queryDslPredicate(OrderDetailQueryRequest queryRequest) {
        QOrderDetail qOrderDetail = QOrderDetail.orderDetail;
        String itemName = queryRequest.getItemName();
        BooleanBuilder booleanBuilder = new BooleanBuilder();
        if (!Strings.isNullOrEmpty(itemName)) {
            booleanBuilder.and(qOrderDetail.itemName.contains(itemName));
        }
        return booleanBuilder;
    }
}
